package ulmermark.demo.rest.spring;

import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;

public class ProtobufViewResolver implements ViewResolver {
	private static final Logger LOGGER = Logger.getLogger(ProtobufViewResolver.class);
	
	final Map<String, View> views;
			
	public ProtobufViewResolver(){
		
		views = new ConcurrentHashMap<String, View>();
		
//		views.put("orders-show", new OrderProtobufView());
//		views.put("orders-index", new OrdersProtobufView());
		views.put("orders-show.proto", new OrderProtobufView());
		views.put("orders-index.proto", new OrdersProtobufView());
		
	}

	@Override
	public View resolveViewName(String viewName, Locale arg1) throws Exception {
		// TODO Auto-generated method stub

		LOGGER.debug(viewName+ "/" + arg1);
		final View view = views.get(viewName);
		LOGGER.debug(view);
		return view;
	}
}
